The aim here is to produce tidal current data in the form of grib files that will work with OpenCPN.
Cygwin and CDO can be used to convert Copernicus netCDF (.nc) files to tidal current gribs for display using OpenCPN.
Using Cygwin you are working with a Linux like environment running under the Windows OS that can be used with the command line or a script to run the CDO program.
The CDO program is an extensive suite of tools. Only a minute fraction of it's power is being used here.
==== Requirements ====
* Cygwin Software
* CDO Program
* Access to Copernicus CMEMS
Downloading Copernicus netCDF (.nc) files requires registration with the CMEMS service of Copernicus. Apply here: Registration
This exercise was undertaken with Windows 8.1 (64bit).
* Install cygwin: From cygwin.com download the setup file … setup-x86_64.exe. Run this file from any suitable location.
A number of additional Cygwin packages are needed in order to run CDO. These are the ones found necessary on my machine:
gcc-core, gcc-fortran, libssl-devel, openssl, curl, zlib, netcdf-devel, udunits, proj, hdf5, netcdf13, libproj13, fftw3
By selecting “Full” you can use the search function to pick out the packages. The latest versions were used.
* Once all the packages have been selected you can press 'Next'. Everything gets installed. The default folder 'C:\cygwin64\' was used.
* The only version of cdo that would run on my machine was found as a posting on the cdo forum here.
'cdo.exe' is extracted and placed in the 'bin' folder of Cygwin.
Add the Cygwin 'bin' folder to the System Environment Variables path variable.
Cygwin can be started from the shortcut or by navigating to the base folder of the installation 'C:\cygwin64\ and running the batch file 'Cygwin.bat'.
During the installation of Cygwin a user folder will have been set up … in my case 'C:\cygwin64\home\Mike'. To test that we have all the dependencies needed to run CDO navigate to the 'bin' folder and run the command 'ldd cdo.exe'. On the first run I found that some packages were missing from Cygwin and it was necessary to run setup-x86_64.exe again to install them.
By closing and restarting the batch file we return to the user directory.
Important: Downloading Copernicus netCDF (.nc) files requires registration with the CMEMS service of Copernicus. Apply here: Registration
Once register navigate to the download page and adjust the area to cover only the Irish Sea. (Selecting the whole area first shown results in too large a file to easily process)
Follow the instructions to download the file.
A netCDF file of the Irish Sea tidal currents ('is.nc') was downloaded from Copernicus and placed in the user directory. By running the command 'cdo sinfon is.nc' the tidal current parameters are listed as vo and uo.
When conversion to Grib takes place these would not be recognised. It is necessary to change the parameter names in the netCDF file to var50 and var49 respectively.
A shell script was made for this but the cdo commands can also be run one at a time.
#!/bin/sh\\ #\\ # change name of uo variable\\ cdo chname,uo,var49 is.nc is1.nc\\ # change name of vo variable\\ cdo chname,vo,var50 is1.nc is2.nc\\ # convert the netCDF file to grib1\\ cdo -f grb copy is2.nc is.grb
The next screenshot shows a conversion for English Channel tidal currents.
Here is the result for the conversion of Irish Sea tidal currents:
Using information from this blog a 'cmd' file was made:
@echo off\\
setlocal
if not exist "%~dpn0.sh" echo Script "%~dpn0.sh" not found & exit 2
set _CYGBIN=C:\cygwin64\bin\\\
if not exist "%_CYGBIN%" echo Couldn't find Cygwin at "%_CYGBIN%" & exit 3
:: Resolve ___.sh to /cygdrive based *nix path and store in %_CYGSCRIPT%\\
for /f "delims=" %%A in ('%_CYGBIN%cygpath.exe "%~dpn0.sh"') do set _CYGSCRIPT=%%A
:: Throw away temporary env vars and invoke script, passing any args that were passed to us\\
endlocal & %_CYGBIN%bash --login "%_CYGSCRIPT%" %*
The command file was placed in the root directory of Cygwin.
Next a shell script was made:
\\ #!/bin/sh\\ #\\ # change name of uo variable\\ cdo chname,uo,var49 is.nc is1.nc\\ # change name of vo variable\\ cdo chname,vo,var50 is1.nc is2.nc\\ # convert the netCDF file to grib1\\ cdo -f grb copy is2.nc is.grb
This is also placed in the root directory. Both the command file and the script are given the same name, only the file ending is different.
The netCDF (.nc) file downloaded from Copernicus is placed in the user folder.
Running 'is.cmd' produces the grib file 'is.grb' in the user folder, in my case 'C:\cygwin64\home\Mike'.